<?php
// 设置头部
header('Content-Type: text/plain');

// 打印HTTP响应信息
echo "===== 测试API响应 =====\n\n";

// 设置请求参数
$url = 'http://localhost/api/orders.php?action=get&id=1';
$headers = ['X-Requested-With: XMLHttpRequest'];

// 创建cURL会话
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, true);

// 执行请求
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// 输出请求信息
echo "请求URL: $url\n";
echo "请求头: " . json_encode($headers, JSON_UNESCAPED_UNICODE) . "\n\n";

// 输出响应信息
echo "响应状态码: $status_code\n";
echo "响应头:\n$headers\n";
echo "响应体:\n$body\n";

// 关闭cURL会话
curl_close($ch);
?> 